<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use yii\web\UploadedFile;

/**
 * UploadForm is the model behind the upload form.
 */
class SelectImageForm extends Model
{
	/**
	 * @var UploadedFile file attribute
	 */
	
	public $name;
	/**
	 * item_preview
	 */
	public $item_id;
	public $fid;
	public $mid;
	public $small_img_id;
	public $thumb_img_id;
	public $big_img_id;
	public $b_t_s_img_id;
	
	public $pid;
	public $model_p;
	/**
	 * @return array the validation rules.
	 */
	public function rules()
	{
		$itempreview = new ItemPreview();
		return [
		
		['name','string'],
		[['name'],'required'],
		
		[['item_id', 'fid', 'mid', 'pid','small_img_id','thumb_img_id','big_img_id','b_t_s_img_id'], 'integer'],
		['item_id','required'],
		[['fid', 'mid', 'item_id'], 'unique', 'targetAttribute' => ['fid','mid','item_id'], 'message' => Yii::t('app','The combination of Item ID, Fid and Mid has already been taken.')],
		
		['big_img_id','checkimage'
			
		],
		
		];
	}
	public function checkimage($attribute,$params){
		//if( $this->big_img_id == null)
		//if(attributes ==null  && $params == null)
		//{
			return false;
			$this->addError($attribute, '该TAG已经存在!');
	//	}
	}
	public function attributeLabels()
	{
		return [
			'file' => Yii::t('app','Image File'),
			'name' => Yii::t('app','Image Name'),
			'fid' => Yii::t('app','Fid'),
			'mid' => Yii::t('app','Mid'),
		];
	}
	public function scenarios()
	{
		$scenarios = parent::scenarios();
		$scenarios['no_need_file_name'] = ['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id'];
		$scenarios['need_file_name'] = ['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id', 'name'];
		$scenarios['item_preview'] = ['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id','item_id', 'fid', 'mid'];
		$scenarios['item_preview_angle'] = ['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id'];
		$scenarios['upload_img'] = ['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id', 'name'];
		return $scenarios;
	}
	public function getModel()
	{
		return $this->model_p = ItemPreview::find()->all();
	}

	
}